def line2int(linea):
temp = ""
for i in linea:
if i == " ":
if temp != "":
val1 = int(temp)
temp = ""
else:
temp = temp + i
val2 = int(temp)
return (val1,val2)
(a,b) = line2int(input())
num2a = num2b = 0
num3a = num3b = 0
num5a = num5b = 0
while a%2==0:
a = int(a/2)
num2a = num2a + 1
while a%3==0:
a = int(a/3)
num3a = num3a + 1
while a%5==0:
a = int(a/5)
num5a = num5a + 1
while b%2==0:
b = int(b/2)
num2b = num2b + 1
while b%3==0:
b = int(b/3)
num3b = num3b + 1
while b%5==0:
b = int(b/5)
num5b = num5b + 1
if a==b: print(abs(num2a-num2b)+abs(num3a-num3b)+abs(num5a-num5b))
else: print(-1)
#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10;
#define ll long long int
#define pb push_back
//#define getUnique(v) {sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());}
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll binexp(ll n,ll p){ll res = 1;while (p>0){if(p&1)res=res*n;n=n*n;p>>=1;}return res;}
void solve(){
ll a,b;
cin>>a>>b;
ll sum=0;
ll x=0,y=0;
while(a%2==0)a/=2,x++;
while(b%2==0)b/=2,y++;
sum+=abs(y-x);
x=0,y=0;
while(a%3==0)a/=3,x++;
while(b%3==0)b/=3,y++;
sum+=abs(y-x);
x=0,y=0;
while(a%5==0)a/=5,x++;
while(b%5==0)b/=5,y++;
sum+=abs(y-x);
if(a!=b)cout<<"-1\n";
else cout<<sum<<"\n";
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
int t;t=1;
while(t--)
solve();
}
137. Single Number II | 130. Surrounded Regions |
129. Sum Root to Leaf Numbers | 120. Triangle |
102. Binary Tree Level Order Traversal | 96. Unique Binary Search Trees |
75. Sort Colors | 74. Search a 2D Matrix |
71. Simplify Path | 62. Unique Paths |
50. Pow(x, n) | 43. Multiply Strings |
34. Find First and Last Position of Element in Sorted Array | 33. Search in Rotated Sorted Array |
17. Letter Combinations of a Phone Number | 5. Longest Palindromic Substring |
3. Longest Substring Without Repeating Characters | 1312. Minimum Insertion Steps to Make a String Palindrome |
1092. Shortest Common Supersequence | 1044. Longest Duplicate Substring |
1032. Stream of Characters | 987. Vertical Order Traversal of a Binary Tree |
952. Largest Component Size by Common Factor | 212. Word Search II |
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |
84. Largest Rectangle in Histogram | 60. Permutation Sequence |